package com.lijinjiang.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName Demo01
 * @Description TODO
 * @Author Li
 * @Date 2022/9/24 18:23
 * @ModifyDate 2022/9/24 18:23
 * @Version 1.0
 */
@WebServlet("/demo01")
public class Demo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 使用 request 对象，获取请求数据
        String name = req.getParameter("name"); // url?name=ZhangSan
        // 使用 request 对象，设置响应数据
        resp.setHeader("content-type", "text/html;charset=utf-8");
        resp.getWriter().write("<h1>" + name + "，欢迎您！</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Request Demo01 doPost...");
    }
}
